using System;
using System.Collections;
using System.Data.Linq.Mapping;
using System.Runtime.Serialization;
using Portal.Data.Helper;
using Portal.Core.Binding.FormBuilder;
using Portal.Core.Helper;
using System.Linq;

namespace Portal.Data.Entity
{
    [Table(Name = "dbo.Page"), Serializable, DataContractAttribute]
    public class Page : BaseObject
    {
        #region Properties
        public int ID { get { return Page_ID; } set { Page_ID = value; } }

        [SkipBinding]
        [Column(Name = "Page_ID", IsPrimaryKey = true, IsDbGenerated = true)]
        [DataMember(Order = 1)]
        public int Page_ID { get; set; }

        [Column]
        [DataMemberAttribute(Order = 2)]
        public string Name { get; set; }

        [Column]
        [DataMemberAttribute(Order = 3)]
        public string Content { get; set; }

        #endregion
        #region Methods
        public static Page FindByPrimaryKey(object objectid)
        {
            return FindByPrimaryKey<Page>(objectid);
        }
        public static Page FindByName(string name)
        {
            //getcache  -----------------------
            var parameter = new object[] { typeof(Page).Name, "FindByName", name };
            var obj = CacheHelper.Instance.Get(parameter);
            if (obj == null)
            {
                const string sql = "select * from Page where Name={0}";
                var result = LINQHelper.GetFirst<Page>(sql, name);
                CacheHelper.Instance.Set(parameter, result);
                return result;
            }
            return (Page)obj;
        }

        public static IList ListAll()
        {
            //getcache  -----------------------
            var parameter = new object[] { typeof(Page).Name, "ListAll" };
            var obj = CacheHelper.Instance.Get(parameter);
            if (obj == null)
            {
                const string sql = "select * from Page order by Name";
                var result = LINQHelper.GetList<Page>(sql);
                CacheHelper.Instance.Set(parameter, result);
                return result;
            }
            return (IList)obj;
        }

        #endregion Methods
    }
}
